﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Bluebunnie.Extensions;
using Bluebunnie.Library.Master.ProjectDataSetTableAdapters;
using System.ComponentModel;

namespace Bluebunnie.Library.Master
{
    /// <summary>
    /// Interaction logic for PriceLevel.xaml
    /// </summary>
    public partial class PriceLevel : PulseControl
    {
        tbl_price_levelTableAdapter adapter = new tbl_price_levelTableAdapter();
        tbl_supplierTableAdapter suppAdapter = new tbl_supplierTableAdapter();

        public PriceLevel()
        {
            InitializeComponent();
            Save = (s, e) =>
                {
                    ProjectDataSet dataset = (ProjectDataSet)FindResource("projectDataSet");
                    adapter.Update(dataset.tbl_price_level);
                };

            try
            {
                Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Tidak dapat mengambil data. Pastikan server MySQL telah berjalan.\n\nError:\n{0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        public override void Refresh()
        {
            base.Refresh();

            ProjectDataSet dataset = (ProjectDataSet)FindResource("projectDataSet");
            suppAdapter.Fill(dataset.tbl_supplier);
            adapter.Fill(dataset.tbl_price_level);

            CollectionViewSource source = (CollectionViewSource)FindResource("tbl_supplierViewSource");
            source.View.MoveCurrentToFirst();
        }
    }
}
